﻿using Cemit.PolyProto;
using Cemit.Awaiter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cemit.NetFramework
{
    public static class PolySocketLoginExtensions
    {
        /// <summary>可等待的方法，登录到目标服务器，返回登录结果</summary>
        public static MonoAsyncAction<LoginResult> Login(this PolySocket socket, string name)
        {
            MonoAsyncAction<LoginResult> action = new MonoAsyncAction<LoginResult>();

            socket
                .Send(GetLoginMsg())
                .AddCallback<Msg_Net_LoginResult>(
                    msg => action.ReportResult(msg.Result));

            return action;

            Msg_Net_Login GetLoginMsg()
                => new Msg_Net_Login { Id = name };
        }
    }
}
